package org.example.myleet.p1576;

public class Solution {

    private static final char[] ALPHABETS = new char[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

    public String modifyString(String s) {
        if (s.length() == 1) {
            return s.replace('?', 'a');
        }
        char[] charArr = s.toCharArray();
        if (charArr[0] == '?') {
            if (charArr[1] == '?') {
                charArr[0] = 'a';
            } else {
                charArr[0] = ALPHABETS[(charArr[1] - 'a' + 1) % 26];
            }
        }
        char front = charArr[0];
        for (int i = 1; i < charArr.length; ++i) {
            if (charArr[i] == '?') {
                charArr[i] = ALPHABETS[(charArr[i - 1] - 'a' + 1) % 26];
            }
            if (i < charArr.length - 1 && charArr[i] == charArr[i + 1]) {
                charArr[i] = ALPHABETS[(charArr[i + 1] - 'a' + 1) % 26];
            }
        }
        return new String(charArr);
    }
}
